package NovelBar.controller;

import NovelBar.dto.TypePageDto;
import NovelBar.entity.Book;
import NovelBar.dto.BooksLabelInfo;
import NovelBar.entity.Label;
import NovelBar.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/public/loadAllBook")
    public List<Book> loadAllBook() {
        return bookService.loadAllBook();
    }

    @RequestMapping("/public/loadIsBookByEnd")
    public List<Book> loadIsBookByEnd(String isEnd) {
        return bookService.loadIsBookByEnd(isEnd);
    }

    @RequestMapping("/public/loadBookByLabel")
    public List<Book> loadBookByLabel(String label) {
        return bookService.loadBookByLabel(label);
    }

    @RequestMapping("/public/loadBookByWid")
    public List<Book> loadBookByWid(Integer wid) {
        return bookService.loadBookByWid(wid);
    }

    @RequestMapping("/public/loadBookByLabelNum")
    public List<Map> loadBookByLabelNum(String[] label, int endNum){
        return bookService.loadBookByLabelNum(label,endNum);
    }

    @RequestMapping("/public/getLabelByBookId")
    public List<BooksLabelInfo> getLabelByBookId(Integer id){
        return bookService.getLabelByBookId(id);
    }

    @RequestMapping("/public/loadBookById")
    public Book loadBookById(Integer id) {
        return bookService.loadBookById(id);
    }

    @RequestMapping("/user/insertBook")
    public Integer insertBook(Book book, String bookType) {
        return bookService.insertBook(book, bookType);
    }

    @RequestMapping("/public/loadAllLabel")
    public List<Label> loadAllLabel() {
        return bookService.loadAllLabel();
    }

    @RequestMapping("/admin/deleteBookById")
    void deleteBookById (Integer id) {
        bookService.deleteBookById(id);
    }

    @RequestMapping("/admin/recommendBook")
    public void recommendBook(Integer id) {
        bookService.recommendBook(id);
    }

    @RequestMapping("/public/loadBookByUserid")
    public List<Book> loadBookByUserid(Integer uid) {
        return bookService.loadBookByUserid(uid);
    }

    @RequestMapping("/public/insertUserBook")
    public void insertUserBook(Integer uid, Integer bookid) {
        bookService.insertUserBook(uid, bookid);
    }

    @RequestMapping("/public/deleteUserBook")
    public void deleteUserBook(Integer uid, Integer bookid) {
        bookService.deleteUserBook(uid, bookid);
    }

    @RequestMapping("/public/loadUserBookByUidBookid")
    public boolean loadUserBookByUidBookid(Integer uid, Integer bookid) {
        return bookService.loadUserBookByUidBookid(uid, bookid);
    }

    @RequestMapping("/public/loadUserBookByIsEndLabel")
    public List<Book> loadUserBookByIsEndLabel(String label,String isEnd){
        return bookService.loadUserBookByIsEndLabel(label,isEnd);
    }

    @RequestMapping("/public/addClickByBookId")
    public int addClickByBookId(Integer bookId){
        return bookService.addClickByBookId(bookId);
    }

    @RequestMapping("/public/loadBookByIsFreeIsEndLabel")
    public List<Book> loadBookByIsFreeIsEndLabel(TypePageDto typePageDto){
        return bookService.loadBookByIsFreeIsEndLabel(typePageDto);
    }

    @RequestMapping("/public/searchAuthorAndTitle")
    public List<Book> searchAuthorAndTitle(String input){
        return bookService.searchAuthorAndTitle(input);
    }

    @RequestMapping("/admin/banRecommendBook")
    public void delete13(Integer bid) {
        bookService.delete13(bid);
    }

    @RequestMapping("/user/endBook")
    public void endBook(Integer id) {
        bookService.endBook(id);
    }
}
